function returnFloat1(value) {
    value = Math.round(parseFloat(value) * 10) / 10;
    if (value.toString().indexOf(".") < 0) {
        value = value.toString() + ".0";
    }
    return value;
}

/*产品列表添加到购物车*/
function proListAddCart(productId){
	$(".car_close").click();//打开购物车
	
	var productName = $("#productName"+productId).html();
	var productDetailded = $("#productDetailded"+productId).html();
	var trueprice = $("#trueprice"+productId).html();
	var imageurl = $("#imageurl"+productId).attr("src");
	var productStartTime = $("#productStartTime"+productId).html();
	var productEndTime = $("#productEndTime"+productId).html();
	
	//判断是否有相同的菜品
	if($("#"+productId).html() != null){
		var num = parseInt($("#num"+productId).html())+1;
		$("#num"+productId).html(num);
		var price = parseFloat($("#cprice"+productId).html())*num;
		$("#ctrueprice"+productId).html(price);
	}else{
		var cartHtml = '<li class="catedLi" id="'+productId+'"><span class="img_pic"><i></i><img src="'+imageurl+'" id="cimageurl'+productId+'"/></span><p><span id="cproductName'+productId+'">'+productName+'</span><span id="productDetailded'+productId+'">'+productDetailded+'</span></p><div class="car_p_total"><strong>￥<font id="ctrueprice'+productId+'">'+trueprice+'</font><font id="cprice'+productId+'" style=" display:none;">'+trueprice+'</font></strong><span class="close" onclick="proCartRemove('+productId+', \'-\');"></span><h3><b class="jian" onclick="proCartNum('+productId+', \'-\');"></b><b id="num'+productId+'">1</b><b class="jia" onclick="proCartNum('+productId+', \'+\');"></b></h3><font id="cStartTime'+productId+'" style="display:none;">'+productStartTime+'</font><font id="cEndTime'+productId+'" style="display:none;">'+productEndTime+'</font></div></li>';
		$(".carInfoList").append(cartHtml);
	}
	
	cartDispose();
	
	if(userId<=0){
		if(isNoLogin == 0){
			$(".user_add_address_span").click();
			return;
		}
	}
}

/*数量加减*/
function proCartNum(productId,typeStr){
	if(typeStr == "+"){
		var num = parseInt($("#num"+productId).html())+1;
		$("#num"+productId).html(num);
		var price = parseFloat($("#cprice"+productId).html())*num;
		$("#ctrueprice"+productId).html(price);
	}else{
		var num = parseInt($("#num"+productId).html());
		if(num == 1){
			alert("数量不能再少了");
			return;	
		}
		num = num - 1;
		$("#num"+productId).html(num);
		var price = parseFloat($("#cprice"+productId).html())*num;
		$("#ctrueprice"+productId).html(price);
	}
	
	cartDispose();
}

/*购物车删除*/
function proCartRemove(productId){
	$("#"+productId).remove();
	
	cartDispose();
}
/*
添加到购物车
*/
function proAddCart(){
	$(".car_close").click();//打开购物车
	
	
	var productId = $("#proId").html();
	var productName = $("#productName").html();
	var productDetailded = $("#productproductDetailded").html();
	var trueprice = $("#proTrueprice").html();
	var imageurl = $("#productImg").attr("src");
	
	//判断是否有相同的菜品
	if($("#"+productId).html() != null){
		var num = parseInt($("#num"+productId).html())+1;
		$("#num"+productId).html(num);
		var price = parseFloat($("#cprice"+productId).html())*num;
		$("#ctrueprice"+productId).html(price);
	}else{
		var cartHtml = '<li class="catedLi" id="'+productId+'"><span class="img_pic"><i></i><img src="'+imageurl+'" id="cimageurl'+productId+'"/></span><p><span id="cproductName'+productId+'">'+productName+'</span><span id="productDetailded'+productId+'">'+productDetailded+'</span></p><div class="car_p_total"><strong>￥<font id="ctrueprice'+productId+'">'+trueprice+'</font><font id="cprice'+productId+'" style=" display:none;">'+trueprice+'</font></strong><span class="close" onclick="proCartRemove('+productId+', \'-\');"></span><h3><b class="jian" onclick="proCartNum('+productId+', \'-\');"></b><b id="num'+productId+'">1</b><b class="jia" onclick="proCartNum('+productId+', \'+\');"></b></h3></div></li>';
		$(".carInfoList").append(cartHtml);
	}
	$(".layer").hide();
	$('.proInfoBox').hide();
	
	cartDispose();
	
	if(userId<=0){
		if(isNoLogin == 0){
			$(".user_add_address_span").click();
			return;
		}
	}
}

/*
购物车变化处理
*/
var submitNum = 0;
function cartDispose(){
	submitNum ++;
	var cartIDArray = ""; //ID
	var cartNumArray = ""; //数量
	var cartTruepriceArray = ""; //单价
	var cartNameArray = ""; //名称
	var cartDetaildedArray = ""; //描述
	var cartUrlArray = ""; //图片
	var cartAddressId = ""; //会员地址ID
	var cartAddrId = ""; //地址ID
	var cartStartTimeArray = ""; //开始时间
	var cartEndTimeArray = ""; //结束时间
	
	cartAddressId = $("#selected_addressId").val();
	cartAddrId = $("#selected_addrId").val();

	//用于购物车第三方统计
	var statistics_str = "";
	
	//获取购物车数据
	var cartData = $(".catedLi");
	if(cartData.html() != null){
		var str = "";
		var str2 = "";
		$.each(cartData, function(key, value){
			var productId = $(value).attr("id");
			cartIDArray += str+productId;
			
			
			var num = parseInt($("#num"+productId).html());
			cartNumArray += str+num;
			
			var ctrueprice = parseFloat($("#cprice"+productId).html());
			cartTruepriceArray += str+ctrueprice;
			
			var productName = encodeURIComponent($("#cproductName"+productId).html());
			cartNameArray += str+productName;
			
			var productDetailded = encodeURIComponent($("#productDetailded"+productId).html());
			cartDetaildedArray += str+productDetailded;
			
			var cimageurl = encodeURIComponent($("#cimageurl"+productId).attr("src"));
			cartUrlArray += str+cimageurl;
			
			var cartStartTime = encodeURIComponent($("#cStartTime"+productId).html());
			cartStartTimeArray += str+cartStartTime;
			
			var cartEndTime = encodeURIComponent($("#cEndTime"+productId).html());
			cartEndTimeArray += str+cartEndTime;
			
			statistics_str += str2+productId+","+num;
			
			str = ",";
			str2 = ";";
			
			/*
			cartArry[0] = new Array();
			cartArry[0]['productId'] = productId;
			cartArry[0]['productName'] = $("#cproductName"+productId).html();
			cartArry[0]['cimageurl'] = $("#cimageurl"+productId).attr("src");
			cartArry[0]['productDetailded'] = $("#productDetailded"+productId).html();
			cartArry[0]['num'] = parseInt($("#num"+productId).html());
			cartArry[0]['ctrueprice'] = parseInt($("#cprice"+productId).html())*cartArry[productId]['num'];*/
		});
		$.ajax({
			url:cartDisposeUrl,
			type:'post',
			dataType:"json",
			data:"cartIDArray="+cartIDArray+"&cartNumArray="+cartNumArray+"&cartTruepriceArray="+cartTruepriceArray+"&cartNameArray="+cartNameArray+"&cartDetaildedArray="+cartDetaildedArray+"&cartUrlArray="+cartUrlArray+"&cartAddressId="+cartAddressId+"&cartAddrId="+cartAddrId+"&cartStartTimeArray="+cartStartTimeArray+"&cartEndTimeArray="+cartEndTimeArray,
			global:false,
			success:function(data){
				if(data.code==0){
					$(".cartips").empty();
					$.each(data.data.couponList, function(k,v){
						var couponsPriceX = "";
						if(v.priceX){
							couponsPriceX = '<samp>￥</samp><b>'+v.priceX+'</b>';
						}
						var coupon = '<div class="cartipslist"><img src="'+api_url+v.couponsLogo+'" /><span>'+v.couponsName+'</span>'+v.couponsDec+couponsPriceX+'<div style=" clear:both;"></div></div>';
						$(".cartips").append(coupon);
					});
					$("#cartPamount").html(data.data.moneyList.originPriceSum);
					$("#cartKamount").html(data.data.moneyList.freePriceSum);
					$("#cartAmount").html(data.data.moneyList.truePriceSum);
					$("#cartSamount").html(data.data.moneyList.sendPrice);
					submitNum--;
					
					!function(w,d,e){
						var _money=data.data.moneyList.truePriceSum;
						var _productList=statistics_str;
						var b=location.href,c=d.referrer,f,s,g=d.cookie,h=g.match(/(^|;)\s*ipycookie=([^;]*)/),i=g.match(/(^|;)\s*ipysession=([^;]*)/);if (w.parent!=w){f=b;b=c;c=f;};u='//stats.ipinyou.com/cvt?a='+e('ft.mo.HgpM9sZH9_oru2hEpAvMiX')+'&c='+e(h?h[2]:'')+'&s='+e(i?i[2].match(/jump\%3D(\d+)/)[1]:'')+'&u='+e(b)+'&r='+e(c)+'&rd='+(new Date()).getTime()+'&Money='+e(_money)+'&ProductList='+e(_productList)+'&e=';
						function _(){if(!d.body){setTimeout(_(),100);}else{s= d.createElement('script');s.src = u;d.body.insertBefore(s,d.body.firstChild);}}_();
					}(window,document,encodeURIComponent);
				}
			}
		});
	//如果购物车已经为空的话
	}else{
		$.ajax({
			url:cartDisposeUrl,
			type:'post',
			dataType:"json",
			data:"cartIDArray=&cartNumArray=&cartTruepriceArray=&cartNameArray=&cartDetaildedArray=&cartUrlArray="+"&cartAddressId="+cartAddressId+"&cartAddrId="+cartAddrId,
			global:false,
			success:function(data){
				if(data.code==0){
					$(".cartips").empty();
					$.each(data.data.couponList, function(k,v){
						var coupon = '<div class="cartipslist"><img src="'+api_url+v.couponsLogo+'" /><span>'+v.couponsName+'</span>'+v.couponsDec+'<samp>￥</samp><b>'+v.priceX+'</b><div style=" clear:both;"></div></div>';
						$(".cartips").append(coupon);
					});
					$("#cartPamount").html(data.data.moneyList.originPriceSum);
					$("#cartKamount").html(data.data.moneyList.freePriceSum);
					$("#cartAmount").html(data.data.moneyList.truePriceSum);
					$("#cartSamount").html(data.data.moneyList.sendPrice);
					submitNum--;
					
					!function(w,d,e){
						var _money="";
						var _productList="";
						var b=location.href,c=d.referrer,f,s,g=d.cookie,h=g.match(/(^|;)\s*ipycookie=([^;]*)/),i=g.match(/(^|;)\s*ipysession=([^;]*)/);if (w.parent!=w){f=b;b=c;c=f;};u='//stats.ipinyou.com/cvt?a='+e('ft.mo.HgpM9sZH9_oru2hEpAvMiX')+'&c='+e(h?h[2]:'')+'&s='+e(i?i[2].match(/jump\%3D(\d+)/)[1]:'')+'&u='+e(b)+'&r='+e(c)+'&rd='+(new Date()).getTime()+'&Money='+e(_money)+'&ProductList='+e(_productList)+'&e=';
						function _(){if(!d.body){setTimeout(_(),100);}else{s= d.createElement('script');s.src = u;d.body.insertBefore(s,d.body.firstChild);}}_();
					}(window,document,encodeURIComponent);
				}
			}
		});
	}
}

/*
产品搜索
*/
function productSearch(){
	var key = $(".input_txt").val();
	if(key == ""){
		alert("请输入您想吃的");	
		return false;
	}
	
	window.location.href = "/index.php/Home/Product/search/key/"+key+".html";
};


/*购物车结算请求*/
function goToClearing(url){
	_smq.push(['custom','cart','pay']);
	pyCvt('购物车#进入结算#');
	
	if(submitNum != 0 ){
		alert("请稍侯，正常获取优惠信息...");
		return false;	
	}
	var productId = getCookie("productIds");
	if(productId){
		window.location.href = url;
	}else{
		alert("您购物车还没有产品哦！！！");	
	}
}
//读取cookies 
function getCookie(name) 
{ 
    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
 
    if(arr=document.cookie.match(reg))
 
        return unescape(arr[2]); 
    else 
        return null; 
}

//删除cookies
function delCookie(name)
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval=getCookie(name);
    if(cval!=null)
        document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}

//设置cookie
function setCookie(name,value)
{
    var Days = 30;
    var exp = new Date();
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "="+ value + ";expires=" + exp.toGMTString();

}



/*结算页面开始处理--start*/
/*数量加减*/
function clearingProCartNum(productId,typeStr){
	if(typeStr == "+"){
		var num = parseInt($("#num"+productId).html())+1;
		$("#num"+productId).html(num);
		var price = parseFloat($("#cprice"+productId).html())*num;
		$("#ctrueprice"+productId).html(price);
	}else{
		var num = parseInt($("#num"+productId).html());
		if(num == 1){
			alert("数量不能再少了");
			return;	
		}
		num = num - 1;
		$("#num"+productId).html(num);
		var price = parseFloat($("#cprice"+productId).html())*num;
		$("#ctrueprice"+productId).html(price);
	}
	
	clearingCartDispose();
}

/*购物车删除*/
function clearingProCartRemove(productId){
	$("#"+productId).remove();
	
	clearingCartDispose();
}

/*兑换码删除*/
function couponclearingProCartRemove(couponID){
	var couponcode = $(".couponcodeLi[couponid='"+couponID+"']").attr("couponid");
	var regulationId = $(".couponcodeLi[couponid='"+couponID+"']").attr("regulationId");
	var regulationName = $(".couponcodeLi[couponid='"+couponID+"']").attr("regulationName");
	if(regulationName){
	var couponhtml = "<li couponcode='"+couponcode+"' regulationId='"+regulationId+"' regulationName='"+regulationName+"'>"+couponcode+"&nbsp;&nbsp;-&nbsp;&nbsp;"+regulationName+"</li>";
	$('.couponcodeList ul').prepend(couponhtml);
	}
	$(".couponcodeLi[couponid='"+couponID+"']").remove();
	clearingCartDispose();
}


/*
购物车变化处理
*/
var clearingSubmitNum = 0;
function clearingCartDispose(){
	clearingSubmitNum ++;
	var cartIDArray = ""; //ID
	var cartNumArray = ""; //数量
	var cartTruepriceArray = ""; //单价
	var cartNameArray = ""; //名称
	var cartDetaildedArray = ""; //描述
	var cartUrlArray = ""; //图片
	
	var couponIDArray = ""; //ID
	var couponNumArray = ""; //数量
	var couponTruepriceArray = ""; //单价
	var couponNameArray = ""; //名称
	var couponDetaildedArray = ""; //描述
	var couponUrlArray = ""; //图片
	
	var cartIsCouponArray = ""; //是否是优惠产品,兑换码数组
	var regulationIdsArray = "";//兑换活动ID数组
	
	//用于购物车第三方统计
	var statistics_str = "";
	
	//获取购物车数据
	var cartData = $(".catedLi");
	if(cartData.html() != null){
		var str = "";
		var str2 = "";
		$.each(cartData, function(key, value){
			var productId = $(value).attr("id");
			cartIDArray += str+productId;
			
			var num = parseInt($("#num"+productId).html());
			cartNumArray += str+num;
			
			var ctrueprice = parseFloat($("#cprice"+productId).html());
			cartTruepriceArray += str+ctrueprice;
			
			var productName = encodeURIComponent($("#cproductName"+productId).html());
			cartNameArray += str+productName;
			
			var productDetailded = encodeURIComponent($("#productDetailded"+productId).html());
			cartDetaildedArray += str+productDetailded;
			
			var cimageurl = encodeURIComponent($("#cimageurl"+productId).attr("src"));
			cartUrlArray += str+cimageurl;
			
			statistics_str += str2+productId+","+num;
			
			str = ",";
			str2 = ";";
			/*
			cartArry[0] = new Array();
			cartArry[0]['productId'] = productId;
			cartArry[0]['productName'] = $("#cproductName"+productId).html();
			cartArry[0]['cimageurl'] = $("#cimageurl"+productId).attr("src");
			cartArry[0]['productDetailded'] = $("#productDetailded"+productId).html();
			cartArry[0]['num'] = parseInt($("#num"+productId).html());
			cartArry[0]['ctrueprice'] = parseInt($("#cprice"+productId).html())*cartArry[productId]['num'];*/
		});
	}
	
	//获取兑换产品数据
		var couponcodeData = $(".couponcodeLi");
		if(couponcodeData.html() != null){
			var str2 = "";
			$.each(couponcodeData, function(key, value){
				var couponproductId = $(value).attr("couponid");
				var isCoupon = $(value).attr("IsCoupon");
				var regulationId = $(value).attr("regulationId");
				couponIDArray += str2+couponproductId;
				cartIsCouponArray += str2+isCoupon;
				regulationIdsArray += str2+regulationId;
				
				var couponnum = parseInt($("#couponnum"+couponproductId).html());
				couponNumArray += str2+couponnum;
				
				var couponctrueprice = parseFloat($("#couponcprice"+couponproductId).html());
				couponTruepriceArray += str2+couponctrueprice;
				
				var couponproductName = encodeURIComponent($("#couponcproductName"+couponproductId).html());
				couponNameArray += str2+couponproductName;
				
				var couponproductDetailded = encodeURIComponent($("#couponproductDetailded"+couponproductId).html());
				couponDetaildedArray += str2+couponproductDetailded;
				
				var couponcimageurl = encodeURIComponent($("#couponcimageurl"+couponproductId).attr("src"));
				couponUrlArray += str2+couponcimageurl;
				str2 = ",";
			});
		}
		
	$.ajax({
			url:cartDisposeUrl,
			type:'post',
			dataType:"json",
			data:"cartIDArray="+cartIDArray+"&cartNumArray="+cartNumArray+"&cartTruepriceArray="+cartTruepriceArray+"&cartNameArray="+cartNameArray+"&cartDetaildedArray="+cartDetaildedArray+"&cartUrlArray="+cartUrlArray+"&cartIsCouponArray="+cartIsCouponArray+"&regulationIdsArray="+regulationIdsArray+"&couponIDArray="+couponIDArray+"&couponNumArray="+couponNumArray+"&couponTruepriceArray="+couponTruepriceArray+"&couponNameArray="+couponNameArray+"&couponDetaildedArray="+couponDetaildedArray+"&couponUrlArray="+couponUrlArray,
			global:false,
			success:function(data){
				if(data.code==0){
					$(".coltd").empty();
					$.each(data.data.couponList, function(k,v){
						var checkbox = "";
						if(v.isChoose == 1){
							checkbox = '<input onclick="couponInputClick(this, '+v.priceX+')" type="checkbox" name="couponlist[]" value="'+v.idX+','+v.numX+','+v.priceX+'" />';
						}
						var couponOne = "";
						if(v.priceX){
							couponOne = '<span class="s_money"><!--<strong>￥</strong><b>96</b>--><em>享受优惠价</em><samp>'+v.priceX+'元</samp></span>';
						}
						var coupon = '<div class="YH_txt">'+couponOne+checkbox+'<img src="'+api_url+v.couponsLogo+'" /><span class="redColor">'+v.couponsName+'</span><span>'+v.couponsDec+'</span></div>';
						$(".coltd").append(coupon);
					});
					$("#cartPamount").html(data.data.moneyList.originPriceSum);
					$("#cartKamount").html(data.data.moneyList.freePriceSum);
					$("#cartAmount").html(data.data.moneyList.truePriceSum);
					$("#cartAmount2").html(data.data.moneyList.truePriceSum);
					$("#cartAmount3").val(data.data.moneyList.truePriceSum);
					$("#cartSamount").html(data.data.moneyList.sendPrice);integralamount
					$("#integralamount").html(parseInt(data.data.moneyList.truePriceSum));
					
					clearingSubmitNum--;
					
					!function(w,d,e){
						var _money=data.data.moneyList.truePriceSum;
						var _productList=statistics_str;
						var b=location.href,c=d.referrer,f,s,g=d.cookie,h=g.match(/(^|;)\s*ipycookie=([^;]*)/),i=g.match(/(^|;)\s*ipysession=([^;]*)/);if (w.parent!=w){f=b;b=c;c=f;};u='//stats.ipinyou.com/cvt?a='+e('ft.mo.HgpM9sZH9_oru2hEpAvMiX')+'&c='+e(h?h[2]:'')+'&s='+e(i?i[2].match(/jump\%3D(\d+)/)[1]:'')+'&u='+e(b)+'&r='+e(c)+'&rd='+(new Date()).getTime()+'&Money='+e(_money)+'&ProductList='+e(_productList)+'&e=';
						function _(){if(!d.body){setTimeout(_(),100);}else{s= d.createElement('script');s.src = u;d.body.insertBefore(s,d.body.firstChild);}}_();
					}(window,document,encodeURIComponent);
				}
			}
		});
}
/*结算页面完成处理--end*/


/*提交订单*/
function submitOrder(){
	$(".red_btn_w116").val("正在提交...");
	$(".red_btn_w116").attr("disabled",true);
	
	pyCvt('结算#提交订单#');
	
	if(clearingSubmitNum != 0 ){
		alert("请稍侯，正常获取优惠信息...");
		$(".red_btn_w116").val("提交订单");
		$(".red_btn_w116").attr("disabled",false);
		return false;	
	}
	if(userId){
		if(!$("#memberAddressId").val()){
			alert("请确认保存地址");
			$(".red_btn_w116").val("提交订单");
			$(".red_btn_w116").attr("disabled",false);
			return false;
		}
	}else{
		var username = $("#address_add").find("input[name='username']").first().val();
                var city_poi_search = $("#address_add").find("input[name='city_poi_search']").first().val();
                var address = $("#address_add").find("input[name='address']").first().val();
                var phone = $("#address_add").find("input[name='phone']").first().val();
                var poi_search_addressid = $("#address_add").find("input[name='poi_search_addressid']").first().val();
                var poi_search_pioname = $("#address_add").find("input[name='poi_search_pioname']").first().val();
                var poi_search_isbaidu = $("#address_add").find("input[name='poi_search_isbaidu']").first().val();
                var poi_search_lng = $("#address_add").find("input[name='poi_search_lng']").first().val();
                var poi_search_lat = $("#address_add").find("input[name='poi_search_lat']").first().val();
                var poi_search_circleid = $("#address_add").find("input[name='poi_search_circleid']").first().val();
                var poi_search_pioaddress = $("#address_add").find("input[name='poi_search_pioaddress']").first().val();
                var poi_search_keyword = $("#address_add").find("input[name='poi_search_keyword']").first().val();
                var othername = $("#address_add").find("input[name='othername']").first().val();
                
                if(misNullOrEmpty(username)) {
                    alert('姓名不能为空');
					$(".red_btn_w116").val("提交订单");
					$(".red_btn_w116").attr("disabled",false);
                    return;
                }
                if(misNullOrEmpty(city_poi_search)) {
                    alert('请选择送餐城市');
					$(".red_btn_w116").val("提交订单");
					$(".red_btn_w116").attr("disabled",false);
                    return;
                }
                if(misNullOrEmpty(address)) {
                    alert('请输入详细地址');
					$(".red_btn_w116").val("提交订单");
					$(".red_btn_w116").attr("disabled",false);
                    return;
                }
                if(misNullOrEmpty(phone)) {
                    alert('请输入联系电话');
					$(".red_btn_w116").val("提交订单");
					$(".red_btn_w116").attr("disabled",false);
                    return;
                }
                if(!validatemobile(phone)) {
                    alert('请输入正确的手机号码');
					$(".red_btn_w116").val("提交订单");
					$(".red_btn_w116").attr("disabled",false);
                    return;
                }
                if(misNullOrEmpty(poi_search_isbaidu)||(poi_search_isbaidu==0&&misNullOrEmpty(poi_search_addressid))||(poi_search_isbaidu==1&&(misNullOrEmpty(poi_search_pioname)||misNullOrEmpty(poi_search_lng)||misNullOrEmpty(poi_search_lat)||misNullOrEmpty(poi_search_pioaddress)))) {
                    alert('请选择大厦名/小区名');
					$(".red_btn_w116").val("提交订单");
					$(".red_btn_w116").attr("disabled",false);
                    return;
                }
	}
	if($("#isUserAgreement").attr("checked") != true){
		alert("请先同意用户协议！");
		$(".red_btn_w116").val("提交订单");
		$(".red_btn_w116").attr("disabled",false);
		return false;
	}
	var productId = getCookie("productIds");

	
	if(productId){
		_smq.push(['custom','pay','ordersubmit']);
		$("#theform").submit();
	}else{
		alert("您还没有添加任何产品哦！！！");
		$(".red_btn_w116").val("提交订单");
		$(".red_btn_w116").attr("disabled",false);
		return false;
	}
}

/*免登录设置密码*/
function setToPassword(){
	

	_smq.push(['custom','submitsuccess','confirmpassword']);
	pyCvt('订单提交成功#确认密码#');
	
	var password = $("#password").val();
	var confirm_password = $("#confirm_password").val();
	var userAgreement = $("#userAgreement").val();
	var passwordBypass = $("#passwordBypass").val();
	if(password && confirm_password){
		if(password != confirm_password){
			alert("两次的密码设置的不一样，请重新设置！");
			$("#password").val("");
			$("#confirm_password").val("");
			$("#password").focus();
			return false;
		}
	}
	
	if($("#userAgreement").attr("checked") != true){
		$("#userAgreement").focus();
		alert("请选同意用户协议");
		return false;
	}
	
	$.ajax({
		url:set_password,
		type:'post',
		dataType:"json",
		data:"password="+password+"&confirm_password="+confirm_password+"&userAgreement="+userAgreement+"&passwordBypass="+passwordBypass,
		global:false,
		success:function(data){
			if(data.code==0){
				$('.layer').show();
				$(".setpassword_div").show();
			}else{
				alert(data.msg);	
			}
		}
	});
	
	//$("#setPassword").submit();
}
function misNullOrEmpty(strVal) {
    if (strVal == '' || strVal == null || strVal == undefined) {
        return true;
    } else {
        return false;
    }
}

//选择加价购
var couponStatus = 0;
function couponInputClick(e,price){
	if(couponStatus == 0){
		couponStatus = 1;
		if(!price){
			alert("数据好像错误了");
			return false;
		}
		if($(e).attr("checked")==true){
			var cartPrice = parseFloat($("#cartAmount3").val());
			var newCarPrice = returnFloat1(cartPrice+parseFloat(price));
			$("#cartAmount").html(newCarPrice);
			$("#cartAmount2").html(newCarPrice);
			$("#cartAmount3").val(newCarPrice);
			$("#integralamount").html(parseInt(newCarPrice));
		}else if($(e).attr("checked")==false){
			var cartPrice = parseFloat($("#cartAmount3").val());
			var newCarPrice = returnFloat1(cartPrice-parseFloat(price));
			$("#cartAmount").html(newCarPrice);
			$("#cartAmount2").html(newCarPrice);
			$("#cartAmount3").val(newCarPrice);
			$("#integralamount").html(parseInt(newCarPrice));
		}
		couponStatus = 0;
	}
}

/*字符限制*/
function strAstrict(e, len){
	if($(e).val().length>len){
		alert("这里只能输入"+len+"个中文字");
	}
}

/*功夫通会员支付*/
function kungfupaySubmit(){
	//关闭错误提示
	$("#kungfupay_error").hide();
	var paypassword = $("#paypassword").val();
	var orderId = $("#orderId").val();
	var cardno = $("#cardno").val();
	
	if(!paypassword){
		$("#kungfupay_error_info").html("请输入支付密码");
		$("#kungfupay_error_info").css("color","#e70014");
		$("#kungfupay_error").show();
		$("#paypassword").focus();
		return false;
	}
	$.ajax({
			url:pay_submit,
			type:'post',
			dataType:"json",
			data:"paypassword="+paypassword+"&orderId="+orderId+"&cardno="+cardno,
			global:false,
			success:function(data){
				if(data.code==0){
					$("#kungfupay_error_info").html("支付成功，正在跳转中...");
					$("#kungfupay_error_info").css("color","#090");
					$("#kungfupay_error").show();
					setTimeout(1000);
					window.location.href = "/index.php/Home/Product/orderfinish/orderId/"+orderId+".html";	
				}else{
					$("#kungfupay_error_info").html(data.msg);
					$("#kungfupay_error_info").css("color","#e70014");
					$("#kungfupay_error").show();
				}
			}
	});
}

/*选择支付方式提交*/
function seleectpay(){
	
	var pay = $("input=[name='pay'][checked=true]").val();
	
	if(!pay){
		alert("请选择支付方式");
		return false;
	}
	$('#theform').submit();
}

/*优惠券的使用*/
function couponcodeUse(){
	var couponcode = $("#couponcodeID").val();
	var regulationId = $("#couponcodeID").attr("regulationId");
	var regulationName = $("#couponcodeID").attr("regulationName");
	if(!couponcode || !regulationId){
		alert("请选择优惠券");
		return false;
	}
	$.ajax({
			url:couponcodeUseUrl,
			type:'post',
			dataType:"json",
			data:"couponcode="+couponcode+"&regulationId="+regulationId,
			global:false,
			success:function(data){
				if(data.code==0){
					var htmlproductList = "<tr class='couponcodeLi' couponid='"+data.data.couponcode+"' IsCoupon='"+data.data.couponcode+"' regulationId='"+data.data.regulationId+"' regulationName='"+regulationName+"'>";
					htmlproductList += "<td><div class='car_img'><img src='"+data.data.productimgUrl+"' id='couponcimageurl"+data.data.couponcode+"'/><i></i></div><span class='cart_p_name' id='couponcproductName"+data.data.couponcode+"'>"+data.data.productname+"</span></td>";
					htmlproductList += "<td><p class='p_dl' id='couponproductDetailded"+data.data.couponcode+"'>"+data.data.productDetailded+"</p></td>";
					htmlproductList += "<td class='ta_center fa_15'>￥<font id='couponcprice"+data.data.couponcode+"'>"+data.data.productprice+"</font></td>";
					htmlproductList += "<td class='ta_center'><span class='num_op'><b id='couponnum"+data.data.couponcode+"'>"+data.data.productNum+"</b></span></td>";
					htmlproductList += "<td class='ta_center'>已优惠</td>";
					htmlproductList += "<td class='ta_center fa_15'>￥<font id='couponctrueprice"+data.data.couponcode+"'>"+data.data.productprice+"</font></td>";
					htmlproductList += "<td class='ta_center'><span class='cart_remove' onclick='couponclearingProCartRemove("+data.data.couponcode+");'></span></td>";
					htmlproductList += "</tr>";
					$("#productListNew").append(htmlproductList);
					
					//结算页面的变化
					clearingCartDispose();
					
					//清除兑换码
					$(".couponcodeList li[couponcode='"+couponcode+"']").remove();
					$("#couponcodeID").val("");
					$("#couponcodeID").attr("regulationId","");
					$("#couponcodeID").attr("regulationname","");
					
					//订单提交
					
				}else{
					alert(data.msg);
					return false;
				}
			}
	});
}
function couponcodeListOnBlur(){
	if(iscouponcodeList == 0){
		$('.couponcodeList').hide();
	}
}